<?php


namespace App\Admin\Extensions\Nav;


class Links
{
    public function __toString()
    {
        return <<<HTML
<li>
    <a class="clear-cache" href="javascript:;">
      <i class="fa fa-trash"></i>
      <span>清理缓存</span>
    </a>
</li>
<script>
// function cleanUp() {
//     $.ajax({
//         type:'POST',
//         url:'/admin/api/clean_up',
//         data:{},
//         dataType: "json",headers: {
//             'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
//         },
//         success:function(data){
//             alert(data.message);
//         }
//     });
//   }
  
   $(function() {
     $('.clear-cache').off('click').on('click', function() {
        var data = $(this).data();
        Object.assign(data, []);
        
                var process = $.admin.swal({
            "type": "question",
            "showCancelButton": true,
            "showLoaderOnConfirm": true,
            "confirmButtonText": "提交",
            "cancelButtonText": "取消",
            "title": "确认清除缓存",
            "text": "",
            preConfirm: function(input) {
                return new Promise(function(resolve, reject) {
                    Object.assign(data, {
                        _token: $.admin.token,
                        _action: 'App_Admin_Actions_ClearCache',
                        _input: input,
                    });
 resolve(data);
                    $.ajax({
                        method: 'POST',
                        url: '/admin/api/clean_up',
                        data: data,
                        success: function (data) {
                            alert(data.message);
                        },
                        error:function(request){
                            reject(request);
                            alert(data.message);
                        }
                    });
                });
            }
        });
    });
   });

</script>

HTML;
    }

}